import 'package:flutter/material.dart';

class LoadingDialog extends Dialog {
  final String text;

  LoadingDialog({
    Key key,
    this.text,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new Material(
      // 创建透明层
      type: MaterialType.transparency, // 透明类型
      child: new Center(
        // 保证控件居中效果
        child: new SizedBox(
          width: 80.0,
          height: 80.0,
          child: new Container(
            decoration: ShapeDecoration(
              color: Color(0xffffffff),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(
                  Radius.circular(8.0),
                ),
              ),
            ),
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                new CircularProgressIndicator(),
                text != null && text.length > 0
                    ? new Padding(
                        padding: const EdgeInsets.only(
                          top: 10.0,
                        ),
                        child: Text(
                          text,
                          style: new TextStyle(fontSize: 12.0),
                        ),
                      )
                    : Container(),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class SuccessDialog extends Dialog {
  final String text;

  SuccessDialog({Key key, @required this.text}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new Material(
      // 创建透明层
      type: MaterialType.transparency, // 透明类型
      child: new Center(
        // 保证控件居中效果
        child: new SizedBox(
          width: 80.0,
          height: 80.0,
          child: new Container(
            decoration: ShapeDecoration(
              color: Color(0xffffffff),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(
                  Radius.circular(8.0),
                ),
              ),
            ),
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Icon(
                  Icons.done,
                  size: 50,
                  color: Color(0xFF3C86F3),
                ),
                text != null && text.length > 0
                    ? new Padding(
                        padding: const EdgeInsets.only(
                          top: 5.0,
                          bottom: 5.0,
                        ),
                        child: Text(
                          text,
                          style: new TextStyle(fontSize: 12.0),
                        ),
                      )
                    : Container(),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class ErrorDialog extends Dialog {
  final String text;

  ErrorDialog({Key key, @required this.text}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new Material(
      // 创建透明层
      type: MaterialType.transparency, // 透明类型
      child: new Center(
        // 保证控件居中效果
        child: new SizedBox(
          width: 80.0,
          height: 80.0,
          child: new Container(
            decoration: ShapeDecoration(
              color: Color(0xffffffff),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(
                  Radius.circular(8.0),
                ),
              ),
            ),
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Icon(
                  Icons.clear,
                  size: 50,
                  color: Color(0xFF3C86F3),
                ),
                text != null && text.length > 0
                    ? new Padding(
                        padding: const EdgeInsets.only(
                          top: 5.0,
                          bottom: 5.0,
                        ),
                        child: Text(
                          text,
                          style: new TextStyle(fontSize: 12.0),
                        ),
                      )
                    : Container(),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class TextDialog extends Dialog {
  final String text;

  TextDialog({Key key, @required this.text}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new Material(
      // 创建透明层
      type: MaterialType.transparency, // 透明类型
      child: new Center(
        // 保证控件居中效果
        child: Container(
          padding: EdgeInsets.all(10),
          decoration: ShapeDecoration(
            color: Color(0xffffffff),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(
                Radius.circular(8.0),
              ),
            ),
          ),
          child: Text(
            text,
            style: TextStyle(fontSize: 12.0),
          ),
        ),
      ),
    );
  }
}
